function [x]=bootstrapSE(data,gender)

%% prepare data to generate C matrix
T=29;

C = zeros(T,T);
Y = zeros(T,T);
D = zeros(T,T);

% D Matrix: Indicator matrix if individual is present at both dates
  
  %diagonoal entries
  for j = 1:length(D)
  D(j,j) = sum( ~isnan(data(:,j+1)));
  end
  
  %off diagonal entries
  
  for j = 1:length(D)
      for i = j+1:length(D)
          resid = [data(:,j+1) data(:,i+1)];
            t=0;
            resid = resid';
            for l = 1:length(resid)
        if ~isnan(resid(:,l))
            t = t+1;
        end
            end
          D(j,i)=t;
         % D(j,i)=D(i,j);
          clear t resid
      end
  end
  
  % Y Matrix: Matrix of product of earnings of individual at both dates
  
     % diagonoal entries
    for j = 1:length(Y)
        help = data(:,j+1).*data(:,j+1);
        id1 = find(isnan(help));
        help([id1]) = [];
        Y(j,j) = sum(help);
        clear help id1
    end
    
     % off diagonoal entries

     for p = 2:T   
         for j = p+1:T+1
 resid = [data(:,p) data(:,j)];
 t=1;
    for i = 1:length(resid(:,1))
 if ~isnan(resid(i,:))
     resid2(t,:) =  resid(i,:) ;
    t = t+1;
 end
     end
 for l = 1: length(resid2(:,1))
 test(l) = resid2(l,2)*resid2(l,1) ;
 end
Y(p-1,j-1) = sum(test);
clear resid resid2 test t 

end
end
  
% combine Y and D matrix

C= Y./D;

%% stack C matrix

C=reshape(C,[(T)*(T),1]);  
      id1 = find(isnan(C));
        C([id1]) = [];
        
        
%% MDE (with Identity matrix) 

var_z0 = 0;

I = length(C);
   func = @(x) (C-theo(x(1),x(2),x(3),var_z0,0))'*eye(I,I)*(C-theo(x(1),x(2),x(3),var_z0,0)) ;
   x0 = [0.8,0.05,0.0012];
   options = optimset('TolFun',1e-8,'TolX',1e-8,'MaxFunEvals',10000);
   [x] = fminsearch(func,x0,options);
 
end